package com.yueqian.system.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yueqian.framework.entity.ResultEntity;
import com.yueqian.system.converter.XxxConvert;
import com.yueqian.system.entity.Xxx;
import com.yueqian.system.service.XxxService;
import com.yueqian.system.vo.req.XxxReqVO;
import com.yueqian.system.vo.res.XxxResVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/xxx")
public class XxxController {


	@Resource
	private XxxService xxxService;

	@GetMapping("/selectPageData")
	public ResultEntity<Page<XxxResVO>> selectPage(XxxReqVO reqVO) {
		Page<Xxx> xxxIPage = xxxService.selectPageData(reqVO);
		Page<XxxResVO> xxxResVOIPage = XxxConvert.INSTANCE.toPage(xxxIPage);
		return ResultEntity.success(xxxResVOIPage);
	}

	@GetMapping("/selectListData")
	public ResultEntity<List<XxxResVO>> selectListData(XxxReqVO reqVO) {
		List<Xxx> xxxList = xxxService.selectListData(reqVO);
		List<XxxResVO> xxxResVOIPage = XxxConvert.INSTANCE.toResList(xxxList);
		return ResultEntity.success(xxxResVOIPage);
	}

	@GetMapping("/getDetail")
	public ResultEntity<XxxResVO> getDetail(@RequestParam(value = "id", required = false) Long id) {
		Xxx details = xxxService.getDetail(id);
		XxxResVO xxxResVOIPage = XxxConvert.INSTANCE.toRes(details);
		return ResultEntity.success(xxxResVOIPage);
	}

	@PostMapping("/add")
	public ResultEntity<Long> add(@RequestBody XxxReqVO reqVO) {
		return ResultEntity.success(xxxService.add(reqVO));
	}

	@GetMapping("/delete")
	public ResultEntity<Long> delete(@RequestParam(value = "id") Long id) {
		return ResultEntity.success(xxxService.delete(id));
	}
}
